#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>

int main (void)
{
	int n = 100;
	int s;
	pid_t pid = vfork();
	if (-1 == pid) {
		perror ("fork()");
		return -1;
	}
	if (0 == pid) {
		//子进程
		printf ("child: pid = %d  ppid = %d\n", getpid(), getppid());
		getchar ();
		printf ("n = %d\n", ++n);
		exit (0);
	} else {
		//父进程
#if 0
		//wait (&s);
		if (WIFEXITED(s)) {
			printf ("child exit code: %d\n", WEXITSTATUS (s));
		}
		if (WIFSIGNALED(s)) {
			printf ("signal num: %d\n", WTERMSIG(s));
		}
#endif
		printf ("parent: pid = %d  ppid = %d  n = %d\n", getpid(), getppid(), n);
	}
	return 0;
}
